<html>
<head><meta charset="utf-8"><title>TerminatorKind::SwitchInt::switch_ty · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/TerminatorKind.3A.3ASwitchInt.3A.3Aswitch_ty.html">TerminatorKind::SwitchInt::switch_ty</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201534687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/TerminatorKind%3A%3ASwitchInt%3A%3Aswitch_ty/near/201534687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/TerminatorKind.3A.3ASwitchInt.3A.3Aswitch_ty.html#201534687">(Jun 21 2020 at 13:36)</a>:</h4>
<p>I realized that the <code>switch_ty</code> field of <code>TerminatorKind</code> is entirely ignored by Miri. That's always suspicious (at least there should be a consistency check), but its only use in codegen is when <code>targets.len() == 2</code>, which also seems odd. Really the <code>discr</code> type should suffice for basically everything.</p>
<p>However, in trying to remove this field I stumbled over <a href="https://github.com/rust-lang/rust/blob/7adbc0dfeffcb6c2ae489cc97d28f76612c7cdf3/src/librustc_middle/mir/mod.rs#L1697">this use</a> that I cannot find a way to remove. It seems odd to have a field just for pretty-printing though. Any advice/ideas?</p>



<a name="201535021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/TerminatorKind%3A%3ASwitchInt%3A%3Aswitch_ty/near/201535021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/TerminatorKind.3A.3ASwitchInt.3A.3Aswitch_ty.html#201535021">(Jun 21 2020 at 13:47)</a>:</h4>
<p>So... looks the issue is that we can't call <code>discr.ty</code>because we don't have access to the containing <code>mir::Body</code>. All call sites but <a href="https://github.com/rust-lang/rust/blob/72417d84fb51495a4f1d007fb2397a0b2609ab63/src/librustc_middle/mir/mod.rs#L1574">https://github.com/rust-lang/rust/blob/72417d84fb51495a4f1d007fb2397a0b2609ab63/src/librustc_middle/mir/mod.rs#L1574</a> do have the <code>mir::Body</code> available. Maybe we should revamp mir pretty printing to use a scheme like type pretty printing instead of doing weird things with <code>Debug</code></p>



<a name="201536107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/TerminatorKind%3A%3ASwitchInt%3A%3Aswitch_ty/near/201536107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/TerminatorKind.3A.3ASwitchInt.3A.3Aswitch_ty.html#201536107">(Jun 21 2020 at 14:19)</a>:</h4>
<p>(I got rid of switch_ty usage in codegen and am currently waiting for the codegen tests to run)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>